﻿//C++入门.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//main函数的编号就是学习的顺序 比如main1  main2  main3	... ...
//一个项目只能有一个main函数入口
#include <iostream>  //尖括号是引入系统库，便于快速查找库文件，工程自定义的库用双引号引入
using namespace std;
#define Day 7//宏常量  这个数据再也不可以修改
#define Mouth "24"

//文件01：已经整合到【技术测试】项目-基础技术.cpp中

int main()
{
	cout << "============入门之：c++初体验===============" << endl;
	//0.c++初体验
	cout << "Hello World!我开始学习C++啦\n";//输出语句
	int a = 10;//定义一个变量
	cout << "变量a的值为：" << a << endl;
	const int b = 1000;//const修饰的变量也为常量,以后再也不可以修改
	cout << "常量b的值为：" << b << endl;
	cout << "宏常量测试，一周有：" << Day << "天" << endl;//宏常量
	cout << "宏常量测试，一个月有：" << Mouth << "天" << endl;//宏常量
	cout << "数值常量加法测试，宏常量和const常量相加：" << Day + b << endl;//常量相加

	cout << "============整型数据：通常情况下使用int型===============" << endl;
	short s1 = 20;//2字节
	int i1 = 20;//4字节
	long l1 = 20;//4字节
	long long ll1 = 20;//8字节
	//wchar t = '2';//
	cout << "short字节数：" << sizeof(s1) << "\nint字节数：" << sizeof(i1) << "\nlong字节数：" << sizeof(l1) << "\nlong long字节数：" << sizeof(ll1) << endl;

	cout << "============浮点数据：默认情况下只输出六位小数============" << endl;
	float f1 = 2.2f;//4字节
	double d1 = 2.2;//8字节
	float f2 = 3e2;//3*10的2次方
	float f3 = 3e-2;//3*0.1的2次方
	cout << "float字节数：" << sizeof(f1) << "\ndouble 字节数：" << sizeof(d1) << endl;

	cout << "============字符型数据：占一个字符,对应ASCII码===========" << endl;
	char ch = 'a';//创建字符变量需要单引号，引号内只能有一个字符
	cout << "char字节数：" << sizeof(ch) << endl;
	cout << "ch底层对应的ascii码是：" << (int)(ch) << endl;//对应的底层整型数据

	cout << "============转义字符：\n，换行符; \\ 输出\; \t 水平制表符====" << endl;
	cout << "aaaaa\thello world" << endl;
	cout << "aaa\thello world" << endl;
	cout << "aaaaaa\thello world" << endl;

	cout << "============字符串类型写法===============" << endl;
	string str = "hello world! hello world! hello world! hello world! hello world! hello world! hello world! hello world! ";//c++风格字符串
	char str1[] = "hello world!";//c风格写法
	cout << str << str1 << endl;
	cout << "字符串占的字节数：" << sizeof(str) << endl;

	cout << "============bool类型:除了0都是真====================" << endl;
	bool flag = true;
	cout << flag << endl;
	cout << sizeof(bool) << endl;

	cout << "============输入数据测试==================" << endl;
	int  ylx = 10;
	cout << "请输入一个整形数据" << endl;
	cin >> ylx;
	cout << "整形变量ylx的值为：" << ylx << endl;

	float  zlj = 10.25f;
	cout << "请输入一个浮点数据" << endl;
	cin >> zlj;
	cout << "浮点数据zlj的值为：" << zlj << endl;

	cout << "============算术运算:除法和取模运算除数不能为0,两个小数是不可以做取模运算的===============" << endl;
	float ff1 = 10.2f;
	float ff2 = 0.2f;
	int aa1 = 2;
	cout << "加：" << ff1 + ff2 << endl;
	cout << "减：" << ff1 - ff2 << endl;
	cout << "乘：" << ff1 * ff2 << endl;
	cout << "除：" << ff1 / ff2 << endl;
	cout << "摸：" << (int)ff1 % aa1 << endl;

	cout << "============算术运算:++ -- 运算符==========================" << endl;
	int y1 = 20;
	cout << "后置加加：先赋值后运算" << y1++ << endl;
	cout << "前置加加：先运算后赋值" << ++y1 << endl;

	cout << "============赋值运算:= += -= *= /= %= 运算符===============" << endl;
	int y2 = 20;
	int y3 = 0;
	y3 = y2;
	cout << "赋值运算:=" << y3 << endl;
	y3 += y2;
	cout << "赋值运算:+=" << y3 << endl;
	y3 -= y2;
	cout << "赋值运算:-=" << y3 << endl;
	y3 *= y2;
	cout << "赋值运算:*=" << y3 << endl;
	y3 /= y2;
	cout << "赋值运算:/=" << y3 << endl;
	y3 %= y2;
	cout << "赋值运算:%=" << y3 << endl;

	cout << "============比较运算:== != > < >= <= 运算符===============" << endl;
	bool s = 4 == 3;
	cout << "比较运算:==" << s << endl;
	s = 4 >= 3;
	cout << "比较运算:>=" << s << endl;
	s = 4 <= 3;
	cout << "比较运算:<=" << s << endl;
	s = 4 != 3;
	cout << "比较运算:!=" << s << endl;
	s = 4 > 3;
	cout << "比较运算:>" << s << endl;
	s = 4 < 3;
	cout << "比较运算:<" << s << endl;

	cout << "=============逻辑运算：============ ！ && ||================" << endl;
	bool aBool = true;
	bool bBool = false;
	bool cBool = true;
	cout << "逻辑与：" << (aBool && cBool) << endl;
	cout << "逻辑非：" << !aBool << endl;
	cout << "逻辑或：" << (aBool || bBool) << endl;

	cout << "=============选择语句：============ if  else================" << endl;
	int socre = 0;
	cout << "请输入一个分数0-1000" << endl;
	cin >> socre;
	if (socre > 600)cout << "恭喜你考上重点大学" << endl;
	else if (socre > 400 && socre <= 600)cout << "很好，你考上了一般大学" << endl;
	else cout << "很遗憾，下次继续努力" << endl;

	cout << "=============三目运算符============ ？ ：===================" << endl;
	int num11 = 20;
	int num22 = 30;
	int num33 = 30;
	cout << "三目运算符" << (num11 > num22 ? num33 : 0) << endl;

	cout << "=============分支语句============ switch case==============" << endl;
	cout << "请给电影输入您的分数0-10" << endl;
	int socreMovie = 0;
	cin >> socreMovie;
	switch (socreMovie)  //case只能是整型或者字符型
	{
	case 10:
	case 9:
	case 8:
	case 7:
		cout << "很高的评分" << endl;
		break;
	case 6:
	case 5:
		cout << "很差的评分" << endl;
		break;
	default:
		cout << "糟糕透顶" << endl;
		break;
	}

	cout << "=============循环语句============while   do while==============" << endl;
	int i = 0;
	while (i < 200)
	{
		i++;
		cout << "输出为:" << i << endl;
	}
	//10.随机数
	//srand((unsigned int)time(NULL));
	//int rnumber = rand() % 100 + 1;  //生成1-100的随机数
	int random = std::rand() % 100 + 1;

	cout << "请输入一个0-100之间的随机数字" << endl;
	int input = 0;
	while (1)
	{
		cin >> input;
		if (input > random)
		{
			cout << "大了" << endl;
		}
		else if (input < random)
		{
			cout << "小了" << endl;
		}
		else
		{
			cout << "对了" << endl;
			int j = 0;
			do
			{
				j++;
				cout << "恭喜您中奖了，哈哈哈" << j << endl;
			} while (j < 10000);
			break;//退出当前循环
		}
	}

	cout << "=============水仙花数============while   do while==============" << endl;
	for (i = 100; i < 1000; i++)
	{
		int a = i % 10;
		int b = (i / 10) % 10;
		int c = (i / 100) % 10;
		if (a * a * a + b * b * b + c * c * c == i)
		{
			cout << "这是个水仙花数" << i << endl;
		}
	}

	cout << "=============敲桌子============while   do while==============" << endl;
	for (i = 0; i < 100; i++)
	{
		if (i % 7 == 0 || i % 10 == 7 || i / 10 == 7)
		{
			cout << "敲桌子" << endl;
		}
		else
		{
			cout << i << endl;
		}
	}

	cout << "=============嵌套循环==========================" << endl;
	for (int i = 0; i < 10; i++)
	{
		for (int j = 0; j < 10; j++)
		{
			cout << "* ";
		}
		cout << endl;
	}

	cout << "=============9*9乘法表==========================" << endl;
	for (int i = 1; i < 10; i++)
	{
		for (int j = 1; j <= i; j++)
		{
			cout << j << " * " << i << "=" << j * i << " ";
		}
		cout << endl;
	}

	cout << "=============goto===============================" << endl;
	cout << "hello" << endl;
	goto A;
	cout << "world" << endl;
A:
	cout << "好" << endl;

	cout << "=============数组===============================" << endl;
	int arr[5];
	arr[0] = 10;
	arr[1] = 20;
	arr[2] = 30;

	cout << arr[0] << endl;
	cout << arr[1] << endl;
	cout << arr[2] << endl;
	cout << arr[3] << endl;
	cout << arr[4] << endl;

	cout << "=============数组遍历===============================" << endl;
	int arrs[6] = { 200,300,400,100,3020,500 };
	int max = 0;
	for (int i = 0; i < 6; i++)
	{
		if (max < arrs[i])
		{
			max = arrs[i];
		}
	}
	cout << "最大的数是:" << max << endl;
	cout << "数组最后一个元素的下标是：" << (sizeof(arrs) / sizeof(arrs[0]) - 1) << endl;

	system("pause");
	return 0;
}

// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单
// 调试程序: F5 或调试 >“开始调试”菜单

// 入门使用技巧: 
//   1. 使用解决方案资源管理器窗口添加/管理文件
//   2. 使用团队资源管理器窗口连接到源代码管理
//   3. 使用输出窗口查看生成输出和其他消息
//   4. 使用错误列表窗口查看错误
//   5. 转到“项目”>“添加新项”以创建新的代码文件，或转到“项目”>“添加现有项”以将现有代码文件添加到项目
//   6. 将来，若要再次打开此项目，请转到“文件”>“打开”>“项目”并选择 .sln 文件

/*这行代码是我的心头肉，呵呵*/
